package com.finalterm.order.task;

import com.finalterm.order.service.OrderService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * 订单超时处理定时任务
 */
@Slf4j
@Component
@RequiredArgsConstructor
public class OrderTimeoutTask {
    
    private final OrderService orderService;
    
    /**
     * 每小时执行一次超时订单处理
     */
    @Scheduled(cron = "0 0 * * * ?")
    public void handleTimeoutOrders() {
        log.info("开始处理超时订单");
        try {
            orderService.handleTimeoutOrders();
            log.info("超时订单处理完成");
        } catch (Exception e) {
            log.error("超时订单处理失败：{}", e.getMessage(), e);
        }
    }
}
